var city = '邯郸';
function loadXMLDoc()
{
    var xmlhttp;
    if (window.XMLHttpRequest)
    {
        //  IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
        xmlhttp=new XMLHttpRequest();
    }
    else
    {
        // IE6, IE5 浏览器执行代码
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            var json = JSON.parse(xmlhttp.responseText);
            console.log(json);
            var week = document.querySelectorAll("#week li");
            console.log(week);
            for(var i = 0;i < week.length;i++){
                week[i].children[1].innerHTML = json.daily_forecast[i].date.slice(5);
                //console.log(week[i].children[1]);
                week[i].children[2].innerHTML = json.daily_forecast[i].tmp.max+"/"+json.daily_forecast[i].tmp.min+"℃";
                week[i].children[3].innerHTML = json.daily_forecast[i].cond.txt_d;//"/"+json.daily_forecast[i].cond.txt_n;
                week[i].children[4].innerHTML = json.daily_forecast[i].wind.dir;
                week[i].children[5].innerHTML = json.aqi.city.qlty;
            }
            var hour = document.querySelectorAll("#hour li");
            console.log(hour);
            for(var j = 0;j < hour.length;j++){
                hour[j].children[0].innerHTML = json.hourly_forecast[j].date.slice(10);
                hour[j].children[1].innerHTML = json.hourly_forecast[j].tmp+"℃";
                hour[j].children[2].innerHTML = json.hourly_forecast[j].wind.dir;
                hour[j].children[3].innerHTML = json.hourly_forecast[j].wind.sc+"级";
            }

            document.querySelector("#drsg").innerHTML = json.suggestion.drsg.txt;
            document.querySelector("#trav").innerHTML = json.suggestion.trav.txt;
            document.querySelector("#cw").innerHTML = json.suggestion.cw.txt;
            document.querySelector("#uv").innerHTML = json.suggestion.uv.txt;
            document.querySelector("#sport").innerHTML = json.suggestion.sport.txt;
            document.querySelector("#air").innerHTML = json.suggestion.air.txt;

            //document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
        }
    };
    xmlhttp.open("GET","http://bird.ioliu.cn/weather?city="+city,true);
    xmlhttp.send();
}
loadXMLDoc();
document.querySelector("#ipt").addEventListener('change', function () {
    console.log(this.value);
    city = this.value;
    loadXMLDoc();
});